package com.sfdk.admin.data.spritesheetEditor
{
	import flash.display.BitmapData;
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.geom.Matrix;
	import flash.geom.Rectangle;

	public class AnimationDetails extends EventDispatcher
	{
		private var _justReversed : Boolean;
		
		private var _bitmapData : BitmapData;

		public function get bitmapData():BitmapData
		{
			return _bitmapData;
		}

		[Bindable]
		public function set bitmapData(value:BitmapData):void
		{
			if(_reversed && !_justReversed)
			{
				var reverseMatrix : Matrix = new Matrix();
				reverseMatrix.scale(-1, 1);
				reverseMatrix.translate(value.width, 0);
				var newBitmapData : BitmapData = new BitmapData(value.width, value.height, true, 0);
				newBitmapData.draw(value, reverseMatrix);
				_bitmapData = newBitmapData;
			}
			else
			{
				_justReversed = false;
				_bitmapData = value;
			}
			dispatchEvent(new Event(Event.CHANGE));
		}

		public var sourceRect : Rectangle;
		
		[Bindable]
		public var duration : Number = 0;
		public var id : int;
		
		public var xOffset : int;
		public var yOffset : int;
		
		private var _reversed : Boolean;

		public function get reversed():Boolean
		{
			return _reversed;
		}

		[Bindable]
		public function set reversed(value:Boolean):void
		{
			_reversed = value;
			_justReversed = true;
			var reverseMatrix : Matrix = new Matrix();
			reverseMatrix.scale(-1, 1);
			reverseMatrix.translate(bitmapData.width, 0);
			var newBitmapData : BitmapData = new BitmapData(bitmapData.width, bitmapData.height, true, 0);
			newBitmapData.draw(bitmapData, reverseMatrix);
			bitmapData = newBitmapData;
		}

	}
	
	
}